package datastructure.matrix;

/**
 *
 * @author Lei
 */
public class RotateMatrix90Degree {

    public void rotateMatrix90Degree(int[][] matrix, int n) {
        for (int layer = 0; layer < n / 2; ++layer) {
            int first = layer;
            int last = n - 1 - layer;
            for (int i = first; i < last; ++i) {
                //int offset = i - first;
                int top = matrix[first][i]; // save top
                // left -> top
                matrix[first][i] = matrix[n - 1 - i ][first];
                // bottom -> left
                matrix[n - 1 - i ][first] = matrix[last][n - 1-  i];
                // right -> bottom
                matrix[last][n - 1 -i] = matrix[i][last];

                matrix[i][last] = top;
            }
        }
    }

    public static void main(String[] args) {
    }
}
